home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
PROGNG_C
/
TCXL21.LZH
/
TCXL.DOC
next >
Wrap
Text File
|
1988-01-25
|
54KB
|
1,849 lines
TCXL.LIB
An Extended Functions Library for Turbo C
Version 2.1
by Mike Smedley
(c) 1987, 1988 All Rights Reserved
This library is intended to be a supplement to the Turbo C function
library. It was written to be used with the tiny and small memory models.
Several of the functions were written in assembly language without any calls to
the Turbo C function library. This makes it possible for assembly language
programmers to call these functions even if they don't have Turbo C. The
functions in this library are very compact and fast. The following files
should be included in this archive:
TCXL.DOC - the library documentation
TCXL.H - the header file
TCXL.HST - history of changes
TCXL.LIB - the object code library
TCXLDEMO.C - the demonstration program source code
TCXLDEMO.COM - the demonstration program
TCXLDEMO.MAK - the make file used for compiling the demo
TCXLDEMO.PRJ - project file used for compiling the demo
You are free to copy and distribute this library freely, however, if you
find this library of use to you, you are encouraged to register your copy. The
registration cost is $20. Included in this registration cost is technical
support, a free upgrade to the next major revision, and best of all the
complete library source code! Also included in the registration cost are the
shipping and handling costs. This library may not be used in commercial
applications without registration. To register, please send payment to:
Mike Smedley
2441 N.E. Loop 410
San Antonio, TX 78217
Or for more information, call (512) 590-2910, no collect calls please.
DISCLAIMER: The author claims no responsibility for any damages caused by the
use or misuse of this library. This product is distributed "as is" with no
warranty expressed or implied.
Turbo C is a registered trademark of Borland International.
1
Calling Functions from Turbo C
------------------------------
To call these functions from Turbo C, you will need to have a line in your
source code file including the TCXL header file: #include "tcxl.h". To find
out what the syntax is of the functions, refer to this documentation or look
at the TCXL.H file. You will also need to link in the TCXL.LIB file when you
link your program. You can do this one of three ways:
1. environment compile: put 'TCXL.LIB' in your .PRJ file
2. command line compile: tcc myfile tcxl.lib
3. command line link: tlink c0s myfile,myfile,,tcxl cs /c/x
Calling Functions from Assembly Language
----------------------------------------
Turbo C passes its arguments to a function via the stack. Arguments are
pushed onto the stack in reverse order. Turbo C places the underscore symbol
preceeding the function name, so to call the getsf function you must call it by
_getsf. After the call to the function, you must readjust the stack. For
every push on the stack, the stack pointer needs to be incremented by 2. The
return value (if any) will be in the AX register. Functions that return type
long will have the high value in DX and the low value in AX. The functions
that can be called by assembly language are listing in the next section with a
plus sign(+) preceeding their name. Here's an example for the getsf()
function:
EXTRN _getsf:NEAR ; so assembler won't flag an error
mov ax,27 ; maximum length of input string
push ax ; push it onto the stack
mov ax,OFFSET name ; address of string to receive input
push ax ; push it onto the stack
call _getsf ; call the function
add sp,4 ; adjust stack 2 for every argument
or ax,ax ; is return a 0? (Esc not pressed)
jnz exitprog ; no, Esc was pressed, exit program
(rest of program)
2
Overview of Functions
---------------------
attrib - creates an attribute
+ beep - sounds a beep in the speaker
+ biosver - returns the BIOS version date
+ box - draws a box on the screen
+ boxd - draws a box directly on the screen (no BIOS calls)
capsoff - toggles the <Caps Lock> key off
capson - toggles the <Caps Lock> key on
clearkeys - clears the keyboard buffer
+ clockcal - determines if a clock-calendar board is installed
+ clreol_ - clears to the end of line
+ clrscrn - clears the screen and homes the cursor
clrwin - clears a window of the screen
cls - clears the screen and homes the cursor
+ delay_ - delays program execution
+ extmem - determines the amount of extended memory on an AT machine
fcmpdatm - compares 2 file's dates and times
fhide - hides a disk file
+ fill - fills in a region of the screen
+ filld - fills in a region of the screen (no BIOS calls)
gameport - determines if a game port is installed
+ getchf - gets a key from the keyboard from a valid list of characters
+ getktot - gets the total disk space in kilobytes
+ getsf - inputs a string from the keyboard, limiting length
getvol - gets the volume label from a disk drive
+ gotoxy_ - plots cursor coordinates on the screen
home - homes the cursor
kbstat - returns the keyboard status
lcrlf - prints a carriage return and line feed on the printer
+ lprintc - prints a character on the printer
+ lprints - prints a string on the printer
+ lprintsf - prints a string on the printer, formatting width
+ machid - returns the value of the machine ROM ID byte
mathchip - determines if a math coprocessor is installed
+ mode - sets the video mode
numflop - returns the number of floppy disk drives installed
numoff - toggles the <Num Lock> key off
numon - toggles the <Num Lock> key on
numpar - returns the number of parallel ports installed
numser - returns the number of serial ports installed
+ printc - displays a character on the screen at location & attribute
+ printcd - displays a character directly on screen at location & attribute
+ prints - displays a string on the screen at location & attribute
+ printsd - displays a string directly on the screen at location & attribute
prompts - prompts for a string and accepts keyboard input
+ readchat - reads the character and attribute under the cursor
+ readcur - reads the current cursor location
+ revattr - reverses the attribute of char under the current cursor location
+ scrndump - dumps the current CGA screen to the printer
+ setattr - sets the attribute of the character under current cursor location
+ setcursz - sets the cursor size
+ sound_ - sounds a tone in the speaker for specified pitch and duration
+ spc - displays specified number of spaces to the screen
srestore - restores a previously saved CGA screen
3
ssave - saves the current CGA screen
+ strchg - changes all matching characters in a string to another
+ strdel - deletes a substring from within a string
+ strichg - changes all matching chars in a string to another, ignoring case
+ stridel - deletes a substring from within a string, ignore case of letters
+ striinc - determines if one string is included in another, ignoring case
+ strinc - determines if one string is included in another
+ striocc - returns num of occurrences of char within a string, ignore case
strleft - returns a substring from the left of a string
strmid - returns a substring from the middle of a string
+ strocc - returns the number of occurrences of a character within a string
strright - returns a substring from the right of a string
strsetsz - sets a string to a specified size, truncating or concatenating
+ tabstop - calculates a tab stop from given column and tab width
+ timer - returns the value of the BIOS timer
+ vidtype - returns the video display adapter type
wactiv - activates an open window
waitkey - halts execution until a key is pressed
wclear - clears the active window
wclose - closes the active window
wclreol - clears to the end of the active window's line
wgetc - gets a character from the keyboard within active window
wgetchf - gets a character from keyboard within window, controlling input
wgets - gets a string from the keyboard within active window
wgetsf - gets a string from keyboard within active window, limiting length
wgotoxy - plots cursor coordinates within active window
whide - hides a window
wmove - moves an active window to a new location
wopen - opens and activates a window on a CGA screen
wprintc - prints a character in the active window
wprints - prints a string in the active window
wputc - prints a character in the active window at curr cursor location
wputs - prints a string in the active window at current cursor location
wputsf - prints a string in the active window formatting length
wrestore - restores a previously saved window of CGA screen memory
wsave - saves a window of CGA screen memory
wscroll - scrolls the text in the active window, up or down
wsize - adjusts the size of the active window
wtextattr - sets the default text attribute used by some windowing functions
wunhide - reveals a hidden window
+ independent of the Turbo C functions library and preprocessor
4
Detail of Functions
-------------------
Name: attrib
Purpose: creates an attribute
Prototype: int attrib(int fore,int back,int bright,int blink)
Inputs: fore - foreground color code (0-7)
back - background color code (0-7)
bright - intensity (0-1)
blink - blinking (0-1)
Return: attribute
Also see: box boxd fill filld printc printcd prints printsd wopen
Example:
prints(15,10,attrib(7,5,1,0),"Hello, world");
Name: beep
Purpose: sounds a beep in the speaker
Prototype: void beep(void)
Inputs: none
Return: none
Also see: sound_
Example:
beep();
Name: biosver
Purpose: returns the ROM BIOS version date
Prototype: char *biosver(void)
Inputs: none
Return: address of the static string containing the ROM BIOS version date
Also see: machid
Example:
char *romver;
romver=biosver();
printf("ROM BIOS version date is %s\n",romver);
Name: box
Purpose: draws a box on the screen
Prototype: void box(int srow,int scol,int erow,int ecol,int btype,int atr)
Inputs: srow - starting row upper left corner
scol - starting column upper left corner
erow - ending row lower right corner
ecol - ending column
btype - box type (0-3)
atr - attribute
Return: none
Also see: attrib boxd fill filld wopen
Example:
box(0,0,22,79,1,WHITE|_BLUE);
Name: boxd
Purpose: draws a box directly on the screen (no BIOS calls)
5
Prototype: void boxd(int srow,int scol,int erow,int ecol,int btype,int atr)
Inputs: srow - starting row upper left corner
scol - starting column upper left corner
erow - ending row lower right corner
ecol - ending column
btype - box type (0-3)
atr - attribute
Return: none
Also see: attrib box fill filld wopen
Example:
boxd(0,0,22,79,1,WHITE|_BLUE);
Name: capsoff
Purpose: toggles the <CapsLock> key off
Prototype: void capsoff(void)
Inputs: none
Return: none
Also see: capson kbstat numoff numon
Example:
capsoff();
Name: capson
Purpose: toggles the <CapsLock> key on
Prototype: void capson(void)
Inputs: none
Return: none
Also see: capsoff kbstat numoff numon
Example:
capson();
Name: clearkeys
Purpose: clears the keyboard buffer
Prototype: void clearkeys(void)
Inputs: none
Return: none
Also see: waitkey
Example:
int ch;
printf("Press a key: ");
clearkeys();
ch=getche();
Name: clockcal
Purpose: determines if a clock-calendar board is installed (usually this
board will only be in XT machines)
Prototype: int clockcal(void)
Inputs: none
Return: a non-zero value if a clock-calendar board is present
Also see: gameport mathchip numflop numpar numser
Example:
printf("A clock-calendar is%s installed\n",clockcal()?"":" not");
6
Name: clreol_
Purpose: clears to the end of line
Prototype: void clreol_(void)
Inputs: none
Return: none
Also see: clrscrn clrwin
Example:
prints(10,5,LCYAN|_BLUE,"Hello, worldXXXXXXXX");
gotoxy_(10,17);
clreol_();
Name: clrscrn
Purpose: clears the screen and homes the cursor
Prototype: void clrscrn(void)
Inputs: none
Return: none
Also see: clreol_ clrwin
Example:
clrscrn();
Name: clrwin
Purpose: clears a window of the screen
Prototype: void clrwin(srow,scol,erow,ecol)
Inputs: srow - starting row upper left corner
scol - starting column upper left corner
erow - ending row lower right corner
ecol - ending column lower right corner
Return: none
Also see: clreol_ clrscrn
Example:
filld(10,10,20,20,'X',LCYAN|_BLUE);
clrwin(11,11,19,19);
Name: cls
Purpose: clears the screen and homes the cursor
Prototype: void cls(void)
Inputs: none
Return: none
Also see: clreol_ clrwin
Example:
cls();
Name: delay_
Purpose: delays program execution for a specified duration
Prototype: void delay_(unsigned duration)
Inputs: duration - duration (0-65535) ie. 18 = 1 second
Return: none
Also see: timer
Example:
printf("Testing\n1\n");
delay_(36);
printf("2\n");
delay_(36);
7
printf("3\n");
Name: extmem
Purpose: determines the amount of extended memory on an AT machine
Prototype: unsigned extmem(void)
Inputs: none
Return: the amount of extended memory in Kilobytes
Example:
printf("Amt of extended memory = %dK\n",extmem());
Name: fcmpdatm
Purpose: compares the dates and times of 2 files
Prototype: int fcmpdatm(char *fname1,char *fname2)
Inputs: fname1 - address of string containing filename1
fname2 - address of string containing filename2
Return: -1 if less than or equal to, 0 if error, 1 if greater than
Example:
int i;
i=fcmpdatm("C:FILE1.EXT","A:FILE1.EXT");
if(i>0) printf("Backup copy of file needs refreshing\n");
Name: fhide
Purpose: hides a disk file
Prototype: int fhide(char *filename)
Inputs: filename - address of string containing file name
Return: a zero if an error occurred
Example:
if(!fhide("MYFILE.EXT")) {
printf("Could not hide file\n");
exit(1);
}
Name: fill
Purpose: fills in a region of the screen with specified character/attribute
Prototype: void fill(int srow,int scol,int erow,int ecol,int ch,int atr)
Inputs: srow - starting row upper left corner
scol - starting column upper left corner
erow - ending row lower left corner
ecol - ending column lower left corner
ch - character to fill with
atr - attribute of character
Return: none
Also see: attrib box boxd filld wopen
Example:
box(1,1,10,10,3,LMAGENTA|_CYAN);
fill(2,2,9,9,' ',WHITE|_RED);
Name: filld
Purpose: fills in a region of the screen with specified character/attribute
by writing directly to the screen (no BIOS calls)
Prototype: void filld(int srow,int scol,int erow,int ecol,int ch,int atr)
Inputs: srow - starting row upper left corner
8
scol - starting column upper left corner
erow - ending row lower left corner
ecol - ending column lower left corner
ch - character to fill with
atr - attribute of character
Return: none
Also see: attrib box boxd fill wopen
Example:
boxd(1,1,10,10,3,LMAGENTA|_CYAN);
filld(2,2,9,9,' ',WHITE|_RED);
Name: gameport
Purpose: determines if a game port is installed
Prototype: int gameport(int equip)
Inputs: equip - the result from the biosequip() function
Return: a 1 if a game port is installed
Also see: clockcal mathchip numflop numpar numser
Example:
int i;
i=biosequip();
printf("Game port is %sinstalled\n",gameport(i)?"":"not ");
Name: getchf
Purpose: gets a character from the keyboard from a list of valid
characters
Prototype: int getchf(char *valid)
Inputs: valid - address of list of valid characters
Return: the character pressed or the Escape (ASCII 27) if it was pressed
Also see: getsf
Example:
char ch;
printf("Are you sure? ");
ch=getchf("YyNn");
if(ch!='Y'&&ch!='y') {
exit(0);
}
Name: getktot
Purpose: gets the total disk space in kilobytes
Prototype: unsigned getktot(int drive)
Inputs: drive - the drive to check (3 = C:, 4 = D:, etc.)
Return: size of the specified disk in kilobytes, -1 if error
Example:
printf("drive C: contains %u kilobytes\n",getktot(3));
Name: getsf
Purpose: inputs a string of specified length from the keyboard, checking
for the Escape key being pressed
Prototype: int getsf(char *str,int max)
Inputs: str - address of location to receive input string
max - maximum length of the input string
Return: a 1 if the <Esc> key was pressed
Also see: getchf
9
Example:
char age[2];
printf("Enter your age: ");
if(getsf(age,2)) {
printf("Escape was pressed\n");
exit(0);
}
Name: getvol
Purpose: gets the volume label from a disk drive
Prototype: char *getvol(char drive)
Inputs: drive - drive letter
Return: address of a static string containing the volume label or a zero if
the disk has no volume label
Example:
printf("The volume label on drive C is: %s\n",getvol('C'));
Name: gotoxy_
Purpose: set cursor coordinates on the screen
Prototype: void gotoxy_(int row,int col)
Inputs: row - cursor row
col - cursor column
Return: none
Also see: printc printcd prints printsd readcur
Example:
gotoxy_(20,30);
printf("We are at row 20, column 30\n");
Name: home
Purpose: homes the cursor
Prototype: void home(void)
Inputs: none
Return: none
Also see: clrscrn gotoxy_
Example:
home();
printf("We are at row 0, column 0\n");
Name: kbstat
Purpose: determines the status of the keyboard control keys
Prototype: int kbstat(void)
Inputs: none
Return: status word of the keyboard flag
Also see: capsoff capson numoff numon
Example:
if(kbstat()&CTRL) printf("The <Ctrl> key is now being pressed\n");
Name: lcrlf
Purpose: prints a carriage return and line feed on the printer
Prototype: void lcrlf(void)
Inputs: none
Return: none
10
Also see: lprintc lprints lprintsf
Example:
lprints("Hello, world");
lcrlf();
lprintc(FF);
Name: lprintc
Purpose: prints a character on the printer
Prototype: void lprintc(int ch)
Inputs: ch - the character to print
Return: none
Also see: lcrlf lprints lprintsf
Example:
lprints("Hello, world");
lcrlf();
lprintc(FF);
Name: lprints
Purpose: prints a string on the printer
Prototype: void lprints(char *str)
Inputs: str - the address of the string to print
Return: none
Also see: lcrlf lprintc lprintsf
Example:
lprints("Hello, world");
lcrlf();
lprintc(FF);
Name: lprintsf
Purpose: prints a string on the printer, formatting width
Prototype: void lprintsf(char *str,int width)
Inputs: str - the address of the string to print
width - width to print string, uses padding or truncating
Return: none
Also see: lcrlf lprintc lprints
Example:
lprintsf("Hello, world",5);
lcrlf();
lprintc(FF);
Name: machid
Purpose: returns the value of the machine ROM ID byte
Prototype: int machid(void)
Inputs: none
Return: the value of the machine ROM ID byte
Also see: biosver
Example:
if(machid()==IBMPCAT) printf("You have an IBM PC/AT\n");
Name: mathchip
Purpose: determines if a math coprocessor is installed
Prototype: int mathchip(int equip)
11
Inputs: equip - the result from the biosequip() function
Return: a 1 if a math coprocessor is installed
Also see: gameport numflop numpar numser
Example:
int i;
i=biosequip();
printf("Math coprocessor is %sinstalled\n",mathchip(i)?"":"not ");
Name: mode
Purpose: sets the video mode
Prototype: void mode(int mode_code)
Inputs: mode_code - mode code number
Return: none
Also see: vidtype
Example:
mode(4);
printf("We are now in CGA graphics mode\n");
Name: numflop
Purpose: determine the number of floppy disk drives installed
Prototype: int numflop(int equip)
Inputs: equip - the result from the biosequip() function
Return: the number of floppy disk drives installed
Also see: gameport mathchip numpar numser
Example:
int i;
i=biosequip();
printf("Number of floppy disk drives = %d\n",numflop(i));
Name: numoff
Purpose: toggle <NumLock> off
Prototype: void numoff(void)
Inputs: none
Return: none
Also see: capsoff capson kbstat numon
Example:
numoff();
Name: numon
Purpose: toggle <NumLock> on
Prototype: void numon(void)
Inputs: none
Return: none
Also see: capsoff capson kbstat numoff
Example:
numon();
Name: numpar
Purpose: determines the number of parallel ports
Prototype: int numpar(int equip)
Inputs: equip - the result from the biosequip() function
Return: the number of parallel ports installed
12
Also see: gameport mathchip numflop numser
Example:
int i;
i=biosequip();
printf("Number of parallel ports = %d\n",numpar(i));
Name: numser
Purpose: determines the number of serial ports installed
Prototype: int numser(int equip)
Inputs: equip - the result from the biosequip() function
Return: the number of serial ports installed
Also see: gameport mathchip numflop numpar
Example:
int i;
i=biosequip();
printf("Number of serial ports = %d\n",numser(i));
Name: printc
Purpose: prints a character to the screen at a specified location and
attribute
Prototype: void printc(int row,int col,int attr,int ch,int count)
Inputs: row - row
col - column
attr - attribute of character
ch - character to print
count - number of times to print character
Return: none
Also see: attrib printcd prints printsd
Example:
printc(18,60,LGREEN|BLINK,'Z',5);
Name: printcd
Purpose: prints a character directly to the screen at a specified
location and attribute (no BIOS calls)
Prototype: void printcd(int row,int col,int attr,int ch)
Inputs: row - row
col - column
attr - attribute of character
ch - character to print
Return: none
Also see: attrib printc prints printsd
Example:
printcd(18,60,LGREEN|BLINK,'Z');
Name: prints
Purpose: displays a string on the screen at a specified location
and attribute
Prototype: void prints(int row,int col,int attr,char *str)
Inputs: row - cursor row
col - cursor column
attr - character attribute
str - address of string to display
Return: none
13
Also see: attrib printc printcd printsd
Example:
prints(20,10,LRED|_LGREY,"Hello, world");
Name: printsd
Purpose: display a string at a specified location in a specified
attribute directly on the screen (no BIOS calls)
Prototype: void printsd(int row,int col,int attr,char *str)
Inputs: row - cursor row
col - cursor column
attr - character attribute
str - address of string to display
Return: none
Also see: attrib printc printcd prints
Example:
printsd(20,10,LRED|_LGREY,"Hello, world");
Name: prompts
Purpose: prompts for a string and accepts keyboard input
Prototype: void prompts(char *prompt,char *str)
Inputs: prompt - address of string containing prompt
str - address of where to place input string
Return: none
Example:
char name[30];
prompts("Enter your name: ",name);
Name: readchat
Purpose: reads the character and attribute under the cursor
Prototype: int readchat(void)
Inputs: none
Return: integer containing character in low byte and attribute in high byte
Also see: gotoxy_ readcur revattr setattr
Example:
int i;
prints(0,0,LGREEN|_BLUE,"Hello, world");
gotoxy_(0,7);
i=readchat();
gotoxy_(1,0);
printf("character is %c and attribute is %d\n",i,(i>>8));
Name: readcur
Purpose: reads the current cursor location
Prototype: void readcur(int *row,int *col)
Inputs: row - address of location to receive cursor row
col - address of location to receive cursor column
Return: none
Also see: gotoxy_ readchat
Example:
int row,col;
readcur(&row,&col);
prints(0,0,LCYAN|BLINK,"Hello, world");
prints(row,col,LWHITE,"Hello,world");
14
Name: revattr
Purpose: reverses the attribute of the character under the current cursor
location
Prototype: void revattr(int count)
Inputs: count - the number of characters to reverse attribute of
Return: none
Also see: readchat setattr
Example:
prints(0,0,LCYAN|_BLUE,"Hello, world");
gotoxy_(0,0);
revattr(5);
Name: scrndump
Purpose: dumps the current CGA screen to the printer
Prototype: void scrndump(void)
Inputs: none
Return: none
Also see: lprintc lprints lprintsf
Example:
printf("Turn printer on and press a key to continue....");
waitkey();
scrndump();
Name: setattr
Purpose: sets the attribute of the character under the current cursor
location
Prototype: void setattr(int attr,int count)
Inputs: attr - attribute to set character
count - the number of characters to set the attribute of
Return: none
Also see: readchat revattr
Example:
prints(0,0,LCYAN|_BLUE,"Hello, world");
gotoxy_(0,0);
setattr(LRED|BLINK,5);
Name: setcursz
Purpose: sets the cursor size
Prototype: void setcursz(int sline,int eline)
Inputs: sline - start line of cursor (32 for no cursor)
eline - end line of cursor
Return: none
Example:
setcursz(1,7);
printf("The cursor is now large\n");
Name: sound_
Purpose: sounds a tone of specified pitch and duration
Prototype: void sound_(unsigned pitch,unsigned duration)
Inputs: pitch - pitch of tone (0-65535)
duration - duration of tone (0-65535) ie. 18 = 1 second
15
Return: none
Also see: beep
Example:
sound_(255,3);
Name: spc
Purpose: displays a specified number of spaces to the screen
Prototype: void spc(int num)
Inputs: num - number of spaces to display
Return: none
Example:
prints(15,50,7,"0123456789");
gotoxy_(15,53);
spc(3);
Name: srestore
Purpose: restores a previously saved CGA screen
Prototype: void srestore(int *sbuf)
Inputs: sbuf - address of previously saved CGA screen buffer
Return: none
Also see: ssave wsave wrestore
Example:
int *sbuf;
sbuf=ssave();
clrscrn();
srestore(sbuf);
Name: ssave
Purpose: saves the current CGA screen
Prototype: int *ssave(void)
Inputs: none
Return: address of newly created CGA screen buffer or 0 if allocation error
Also see: srestore wsave wrestore
Example:
int *sbuf;
sbuf=ssave();
clrscrn();
srestore(sbuf);
Name: strchg
Purpose: finds all letters in a string matching one character and
replaces them with another
Prototype: void strchg(char *str,char oldch,char newch)
Inputs: str - address of string to search
oldch - character to search for
newch - character to replace with
Return: none
Also see: strichg
Example:
char *str="Hello there";
printf("Before: %s\n",str);
strchg(str,'h','*');
printf("After: %s\n",str);
16
Name: strdel
Purpose: deletes a substring from within a string
Prototype: int strdel(char *substr,char *str)
Inputs: substr - address of substring to delete
str - address of string to delete from
Return: a 0 if the substring was not found in the string
Also see: stridel striinc strinc strmid
Example:
char *str="Hello, XXXXXworld";
strdel("XXXXX",str);
printf("%s\n",str);
Name: strichg
Purpose: finds all letters in a string matching one character and
replaces them with another, ignoring case of letters
Prototype: void strichg(char *str,char oldch,char newch)
Inputs: str - address of string to search
oldch - character to search for
newch - character to replace with
Return: none
Also see: strchg
Example:
char *str="Hello there";
printf("Before: %s\n",str);
strichg(str,'h','*');
printf("After: %s\n",str);
Name: stridel
Purpose: deletes a substring from within a string, ignoring case of letters
Prototype: int stridel(char *substr,char *str)
Inputs: substr - address of substring to delete
str - address of string to delete from
Return: a 0 if the substring was not found in the string
Also see: strdel striinc strinc strmid
Example:
char *str="Hello, XXXXXworld";
stridel("XXXXX",str);
printf("%s\n",str);
Name: striinc
Purpose: determines if one string1 is included in string2, ignoring
case of letters
Prototype: char *striinc(char *str1,char *str2)
Inputs: str1 - address of string1
str2 - address of string2
Return: the address where string1 is included in string2, or a 0 if
string1 is not included in string2
Also see: strinc
Example:
char *str1="HeLlo WOrLd";
char *str2="XXXXXXXHello, worldXXXXX";
if(striinc(str1,str2)) printf("%s is included in %s\n",str1,str2);
17
Name: strinc
Purpose: determines if one string1 is included in string2
Prototype: char *strinc(char *str1,char *str2)
Inputs: str1 - address of string1
str2 - address of string2
Return: the address where string1 is included in string2, or a 0 if
string1 is not included in string2
Also see: striinc strmid
Example:
char *str1="Hello world";
char *str2="XXXXXXXHello, worldXXXXX";
if(strinc(str1,str2)) printf("%s is included in %s\n",str1,str2);
Name: striocc
Purpose: returns the number of occurrences of a character in a string
ignoring the case of letters
Prototype: int striocc(char *str,int ch)
Inputs: str - address of the string to search
ch - the character to look for
Return: the number of occurrences of the character in the string
Also see: strocc
Example:
char ch='L';
char *str="Hello, world";
printf("%c occurs in %s %d times\n",ch,str,striocc(str,ch));
Name: strleft
Purpose: takes a specified portion of a string from the left and creates
a new string
Prototype: char *strleft(char *str,int num_chars)
Inputs: str - address of input string
num_chars - number of characters to copy
Return: address of the newly created string or a 0 if a memory allocation
error occurred
Also see: strdel stridel striinc strinc strmid strright
Example:
char *left;
char *str="Hello, worldXXXX";
left=strmid(str,12);
printf("%s\n",left);
free(left); /* free memory when done with string */
Name: strmid
Purpose: takes a section from input string starting at given position
and taking the given amount of characters creating a new string
Prototype: char *strmid(char *str,int st_pos,int num_chars)
Inputs: str - address of input string
st_pos - position in input string to start copying characters
(starting at position 0)
num_chars - number of characters to copy
Return: address of the newly created string or a 0 if a memory allocation
error occurred
18
Also see: strdel stridel striinc strinc strleft strright
Example:
char *middle;
char *str="XXXXXHello, worldXXXX";
middle=strmid(str,5,12);
printf("%s\n",middle);
free(middle); /* free memory when done with string */
Name: strocc
Purpose: returns the number of occurrences of a character in a string
Prototype: int strocc(char *str,int ch)
Inputs: str - address of the string to search
ch - the character to look for
Return: the number of occurrences of the character in the string
Also see: striocc
Example:
char ch='l';
char *str="Hello, world";
printf("%c occurs in %s %d times\n",ch,str,strocc(str,ch));
Name: strright
Purpose: takes a specifed portion from the right side of a string creating
a new string
Prototype: char *strright(char *str,int num_chars)
Inputs: str - address of input string
num_chars - number of characters to copy
Return: address of the newly created string or a 0 if a memory allocation
error occurred
Also see: strdel stridel striinc strinc strleft strmid
Example:
char *right;
char *str="XXXXXHello, world";
right=strright(str,12);
printf("%s\n",right);
free(right); /* free memory when done with string */
Name: strsetsz
Purpose: adjusts the length of a string by truncation or padding with
spaces
Prototype: char *strsetsz(char **str,int newsize)
Inputs: str - address of pointer to the string
newsize - the new length of the string
Return: address of the new string or a 0 if a memory allocation error
occurred
Example:
char *str="Hello, world";
strsetsz(&str,25);
printf("%s.\n",str);
strsetsz(&str,5);
printf("%s.\n",str);
Name: tabstop
Purpose: calculates a tab stop from given column and tab width
19
Prototype: int tabstop(int col,int tabwidth)
Inputs: col - column
tabwidth - tab width
Return: the next tab stop
Example:
printf("tabstop after column 5 is %d\n",tabstop(5,8);
Name: timer
Purpose: returns the value of the BIOS timer
Prototype: unsigned long timer(void)
Inputs: none
Return: current value of the BIOS timer
Also see: delay_
Example:
printf("%lu\n",timer());
delay_(36);
printf("%ul\n",timer());
Name: vidtype
Purpose: determines the display adapter type
Prototype: int vidtype(void)
Inputs: none
Return: a 2 for EGA, 1 for CGA, or 0 for MDA
Also see: mode
Example:
int i;
i=vidtype();
if(i) printf("A color adapter is installed\n");
Name: wactiv
Purpose: activates a currently open window
Prototype: int wactiv(int whandle)
Inputs: whandle - the window handle returned from the wopen() function
Return: a zero if no error, see TCXL.H for return codes
Also see: wclose wopen
Example:
int w1,w2;
w1=wopen(0,0,20,20,0,LMAGENTA|_RED);
waitkey();
w2=wopen(10,10,15,50,0,LGREEN|_BLUE);
waitkey();
wactiv(w1);
waitkey();
wclose();
wclose();
Name: waitkey
Purpose: halts execution until a key is pressed
Prototype: int waitkey(void)
Inputs: none
Return: the key pressed
Also see: clearkeys
Example:
20
printf("Press any key to continue...");
waitkey();
Name: wclear
Purpose: clears the currently active window
Prototype: void wclear(void)
Inputs: none
Return: none
Also see: wclreol
Example:
wopen(10,10,20,20,0,WHITE|_GREEN);
wprints(11,11,7,"Hello");
wclear();
waitkey();
wclose();
Name: wclose
Purpose: closes the currently active window
Prototype: void wclose(void)
Inputs: none
Return: none
Also see: wmove wopen
Example:
wopen(10,10,20,20,1,LCYAN|_BLUE);
waitkey();
wclose();
Name: wclreol
Purpose: clears to the end of the active window's line
Prototype: void wclreol(void)
Inputs: none
Return: none
Also see: wclear
Example:
wopen(10,10,20,40,0,LMAGENTA|_RED);
wputs("Hello, world");
wgotoxy(0,5);
wclreol();
waitkey();
wclose();
Name: wgetc
Purpose: gets a character from the keyboard within the active window, echos
character pressed to the screen in the attribute set by the
wtextattr() function
Prototype: int wgetc(void)
Inputs: none
Return: the ASCII value of the key pressed
Also see: wgetchf wgets wgetsf wtextattr
Example:
wopen(0,0,5,30,0,LCYAN|_BLUE);
wputs("Press a key: ");
wputs("\nYou pressed %c",wgetc());
21
waitkey();
wclose();
Name: wgetchf
Purpose: gets a character from the keyboard within the active window, allows
only characters listed in the string of valid characters and the
Escape key, echos character pressed to the screen in the attribute
set by the wtextattr() function
Prototype: int wgetchf(char *valid)
Inputs: valid - string containing valid characters
Return: the ASCII value of the key pressed
Also see: wgetc wgets wgetsf wtextattr
Example:
wopen(0,0,5,30,0,LCYAN|_BLUE);
wputs("Are you sure? ");
wputs("\nYou pressed %c",wgetchf("YyNn"));
waitkey();
wclose();
Name: wgets
Purpose: gets a string from the keyboard within active window, echos the
characters to the screen in the attribute set by the wtextattr()
function
Prototype: void wgets(char *str)
Inputs: str - the address of the string to receive the input characters
Return: none
Also see: wgetc wgetchf wgetsf wtextattr
Example:
char fname[20];
wopen(0,0,5,60,0,LCYAN|_BLUE);
wputs("Enter your first name: ");
wgets(fname);
wputs("\nYour first name is: %s",fname);
waitkey();
wclose();
Name: wgetsf
Purpose: gets a string from the keyboard within active window, limits the
number of characters input to specified length, checks for the
Escape key being pressed, echos the characters to the screen in
the attribute set by the wtextattr() function
Prototype: int wgetsf(char *str,int maxlen)
Inputs: str - address of the string to receive the input characters
maxlen - the maximum length of the input string
Return: a non-zero value if the Escape key was pressed, see TCXL.H for
the return codes
Also see: wgetc wgetchf wgets wtextattr
Example:
char fname[20];
wopen(0,0,5,60,0,LCYAN|_BLUE);
wputs("Enter your first name: ");
wgetsf(fname,5);
wputs("\nYour first name is: %s",fname);
waitkey();
22
wclose();
Name: wgotoxy
Purpose: plots cursor coordinates within the currently active window
Prototype: int wgotoxy(int wrow,int wcol)
Inputs: wrow - window row
wcol - window column
Return: a non-zero value if an attempt was made to plot outside of window
Also see: wprintc wprints
Example:
wopen(0,0,10,10,0,YELLOW|_BLUE);
wgotoxy(1,1);
wputs("Hello");
Name: whide
Purpose: hides a window
Prototype: int *whide(int **wbuf)
Inputs: wbuf - address of the pointer to the window buffer to hide
Return: the address of the hidden window's buffer or a 0 if a memory
allocation error occurred
Also see: wclose wopen wrestore wsave wunhide
Example:
wopen(0,0,15,50,0,LCYAN|_BLUE);
waitkey();
whide(&_wrecord[_wcurrent].wbuf);
waitkey();
wunhide(&_wrecord[_wcurrent].wbuf);
waitkey();
wclose();
Name: wmove
Purpose: moves the currently active window to a new location
Prototype: int wmove(int nsrow,int nscol)
Inputs: nsrow - new starting row of window
nscol - new starting column of window
Return: a zero if no error occurred, see TCXL.H for return codes
Also see: wclose wopen wsize
Example:
wopen(10,10,20,20,2,LCYAN|_BLUE);
waitkey();
wmove(0,0);
waitkey();
wclose();
Name: wopen
Purpose: opens a CGA screen window and makes it active, only 10 windows can
be open at a time, registered users may recompile this function to
allow more windows
Prototype: int wopen(int srow,int scol,int erow,int ecol,int btype,int attr)
Inputs: srow - starting row, upper left corner
scol - starting column, upper left corner
erow - ending row, lower right corner
ecol - ending column, lower right corner
23
btype - box type (0-3)
attr - attribute of window
Return: window handle or a zero if an error occurred
Also see: wclose wactiv
Example:
wopen(10,10,20,20,0,LCYAN|_BLUE);
waitkey();
wclose();
Name: wprintc
Purpose: prints a character in the currently active window, does not adjust
cursor
Prototype: int wprintc(int row,int col,int attr,int ch)
Inputs: row - cursor row (of the window)
col - cursor column (of the window)
attr - character attribute
ch - character
Return: non-zero if an attempt was made to plot outside of the window
Also see: wprints wputc wputs wputsf
Example:
wopen(10,10,20,20,0,WHITE|_GREEN);
wprintc(11,11,7,"T");
waitkey();
wclose();
Name: wprints
Purpose: prints a string in the currently active window, does not adjust
cursor
Prototype: int wprints(int row,int col,int attr,char *str)
Inputs: row - cursor row (of the window)
col - cursor column (of the window)
attr - attribute
str - address of string
Return: non-zero if an attempt was made to plot outside of the window
Also see: wprintc wputc wputs wputsf
Example:
wopen(10,10,20,20,0,WHITE|_GREEN);
wprints(11,11,7,"Hello");
waitkey();
wclose();
Name: wputc
Purpose: prints a character in currently active window at current cursor
location, uses attribute set by the wtextattr() function
Prototype: void wputc(int ch)
Inputs: ch - the character to be printed
Return: a non-zero value if current cursor location is not within window
Also see: wgotoxy wprintc wprints wputs wputsf wtextattr
Example:
wopen(10,10,20,20,0,WHITE|_GREEN);
wgotoxy(5,5);
wtextattr(LMAGENTA|BLINK);
wputc('X');
waitkey();
24
wclose();
Name: wputs
Purpose: prints a string in currently active window at the current cursor
location, uses attribute set by the wtextattr() function
Prototype: void wputs(char *str)
Inputs: str - the address of the string to print
Return: a non-zero value if current cursor location is not within window
Also see: wgotoxy wprintc wprints wputc wputsf wtextattr
Example:
wopen(10,10,20,20,0,WHITE|_GREEN);
wgotoxy(1,1);
wtextattr(LMAGENTA|BLINK);
wputs("Hello, world");
waitkey();
wclose();
Name: wputsf
Purpose: prints a string in the active window, formatting width of output,
uses attribute set by the wtextattr() function
Prototype: void wputsf(char *str,int width)
Inputs: str - address of the string to print
width - width to display output string with
Return: none
Also see: wgotoxy wprintc wprints wputc wputs wtextattr
Example:
wopen(10,10,20,20,0,WHITE|_GREEN);
wgotoxy(1,1);
wtextattr(LMAGENTA|BLINK);
wputsf("Hello, world",5);
waitkey();
wclose();
Name: wrestore
Purpose: restores a previously saved window of CGA screen memory
Prototype: void wrestore(int *wbuf)
Inputs: wbuf - address of previously saved window
Return: none
Also see: srestore ssave whide wsave wunhide
Example:
int *wbuf;
wbuf=wsave(7,7,18,60);
clrscrn();
wrestore(wbuf);
Name: wsave
Purpose: saves a window of CGA screen memory
Prototype: int *wsave(int srow,int scol,int erow,int ecol)
Inputs: srow - starting row, upper left corner
scol - starting column, upper left corner
erow - ending row, lower right corner
ecol - ending column, lower right corner
Return: address of newly created window buffer or 0 if allocation error
25
Also see: srestore ssave whide wrestore wunhide
Example:
int *wbuf;
wbuf=wsave(7,7,18,60);
clrscrn();
wrestore(wbuf);
Name: wscroll
Purpose: scrolls text within the active window, up or down
Prototype: void wscroll(int count,int direction)
Inputs: wbuf - the address of the window buffer of the window
count - number of lines to scroll
direction - a 0 to scroll down or non-zero to scroll up
Return: none
Also see: wclose wopen wputc wputs
Example:
wopen(10,10,20,20,0,WHITE|_GREEN);
wprints(11,11,7,"Hello");
waitkey();
wscroll(2,DOWN);
waitkey();
wclose();
Name: wsize
Purpose: adjusts the size of the active window
Prototype: int wsize(int nerow,int necol)
Inputs: nerow - new end row of sized window
necol - new end column of sized window
Return: a zero if no error occurred, see TCXL.H for return codes
Also see: wmove
Example:
wopen(10,10,20,20,0,WHITE|_GREEN);
waitkey();
wsize(23,40);
waitkey();
wsize(15,15);
waitkey();
wclose();
Name: wtextattr
Purpose: sets the default text attribute used by some windowing functions
Prototype: void wtextattr(int attr)
Inputs: attr - the new text attribute
Return: none
Also see: wgetc wgetchf wgets wgetsf wprintc wprints wputc wputs wputsf
Example:
wopen(10,10,20,20,0,WHITE|_GREEN);
wgotoxy(1,1);
wtextattr(LMAGENTA|BLINK);
wputs("Hello, world");
waitkey();
wclose();
26
Name: wunhide
Purpose: unhides a previously hidden window
Prototype: int *wunhide(int **wbuf)
Inputs: wbuf - address of the pointer to the window buffer to unhide
Return: the address of the unhidden window's buffer or a 0 if a memory
allocation error occurred
Also see: whide wrestore wsave
Example:
wopen(0,0,15,50,0,LCYAN|_BLUE);
waitkey();
whide(&_wrecord[_wcurrent].wbuf);
waitkey();
wunhide(&_wrecord[_wcurrent].wbuf);
waitkey();
wclose();
27
Global Variables
----------------
Name: _wcurrent
Purpose: contains the array subscript of the window that is currently active
Type: int
Name: _whandle
Purpose: contains the last handle number given to a window
Type: int
Name: _wrecord
Purpose: an array of window records which contains window handles and window
buffer pointers
Type: struct _wrecord (see TCXL.H for definition)
28